package com.zhoutao.blog.seven.pages;


import com.zhoutao.blog.seven.model.response.Menu;
import com.zhoutao.blog.seven.service.ArticleService;
import com.zhoutao.blog.seven.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/admin")
public class AdminController extends AbstractPageController {

    @Autowired
    private ArticleService articleService;

    @Autowired
    private MenuService menuService;

    @GetMapping("/index")
    public String loginPage(Model model) {
        return "admin/index";
    }


    @GetMapping("/home")
    public String homePage(Model model) {
        return "admin/home";
    }


    @GetMapping("/book")
    public String bookPage(Model model) {
        return "admin/book";
    }


    @GetMapping("/book/category")
    public String bookCategoryPage(Model model) {
        return "admin/bookCategory";
    }


    @GetMapping("/articles")
    public String articlePage(Model model) {
        return "admin/articles";
    }


    @GetMapping("/newArticle")
    public String newArticlePage(Model model, @RequestParam(required = false) Long articleId) {
        packageAdminInfo(model);
        model.addAttribute("article", articleService.findById(articleId));
        return "admin/newArticle";
    }

    //    菜单
    @GetMapping("/menu")
    public String menu(Model model) {
        packageAdminInfo(model);
        List<Menu> menus = menuService.all();
        model.addAttribute("menus", menus);
        return "admin/menu";
    }

    //    菜单
    @GetMapping("/setting")
    public String setting(Model model) {
        packageAdminInfo(model);
        List<Menu> menus = menuService.all();
        model.addAttribute("setting", menus);
        return "admin/setting";
    }


}
